package basic.a1;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Statement;

public class Insert1 {

	public static void main(String[] args) {
		try {
			Class.forName("oracle.jdbc.driver.OracleDriver");
			System.out.println("加载成功");
			Connection con=DriverManager.getConnection("jdbc:oracle:thin:@127.0.0.1:1521:xe","username","password");
			System.out.println("连接成功");
			int id=112;
			String namber="物理";
			String address="昆明";
			/*Statement stm=con.createStatement();
			String sql="insert into department values("+id+",'"+namber+"','"+address+"')";
			int f=stm.executeUpdate(sql);
			System.out.println(f);*/
			String sql="insert into department values(?,?,?)";
			PreparedStatement p=con.prepareStatement(sql);
			p.setInt(1, id);
			p.setString(2, namber);
			p.setString(3, address);
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}

}
